<?php
/*
**	pagination 分页
**	@Author			Alan
**	@Support		Alanyao80@gmail.com
*	@Finish			2008-12-08
*/

class MyPage{
	private $p_size = 20;									//显示记录数
	private $p_display = 9;									//显示页码数,用奇数
	private $p_count=0;										//总记录数
	private $p_tpage=0;										//总页数
	private $p_cpage=1;										//当前页数
	//private $p_first_string='<span>Home</span>';			//首页标志
	//private $p_pre_string='<span>Pre.</span>';				//上一页标志
	//private $p_next_string='<span>Next</span>';			//下一页标志
	//private $p_last_string='<span>Last</span>';			//尾页标志
	private $p_first_string='<span><img src="/public/images/admin/page/1.gif" alt="首页" border="0" /></span>';			//首页标志
	private $p_pre_string='<span><img src="/public/images/admin/page/2.gif" alt="上一页" border="0" /></span>';				//上一页标志
	private $p_next_string='<span><img src="/public/images/admin/page/3.gif" alt="下一页" border="0" /></span>';			//下一页标志
	private $p_last_string='<span><img src="/public/images/admin/page/4.gif" alt="末页" border="0" /></span>';			//尾页标志
	private $db=null;										//数据库连接
	private $isexecute=0;									//判断是否已进行查询
	private $isoption=0;									//是否用下拉菜单
	private $issum=1;										//是否显示总数量
	private $output_sql;											//输出sql	
	private $top_page;											//右上方分页					

	public function __construct($db){
		$this->db=$db;
	}
   
	public function __destruct(){
		unset($this->db);
	}
	
	public function set_style(){
		$this->p_first_string='<span>首页</span>';
		$this->p_pre_string='<span>上一页</span>';
		$this->p_next_string='<span>下一页</span>';	
		$this->p_last_string='<span>末页</span>';
	}
	

	/**
	 * 通过sql获取分布信息,输出当前页数据
	 *
	 * @param string $table
	 * @param array $field
	 * @param string $where
	 * @param string $order
	 * @param int $cpage
	 * @param int $size
	 * @return array
	 */
	public function from_sql($field='*',$table,$where='',$order='',$cpage=1,$size=20){
		if(!$table || !$field)
		my_jump('请指定数据表与字段');
		$this->p_cpage = intval($cpage) ? intval($cpage) : 1;
		$this->p_size = intval($size);

		$where = $where ? " WHERE ".$where : '';
		//die ($where);
		$order = $order ? " ORDER BY ".$order : '';
		$this->output_sql = "SELECT ".$field." FROM ".$table.$where.$order;
		$sql1 = "SELECT count(*) FROM ".$table.$where.$order;
		//$sql = "SELECT ".$field." FROM ".$table.$where.$order;
		$this->p_count = $this->db->getOne($sql1);
		
		$data=array();
		if ($this->p_count > 0 ){
			if ($this->p_count < $this->p_size){
				$this->p_tpage = 1;
			}
			else{
				$this->p_tpage = ceil ( $this->p_count/$this->p_size );
			}
			$f_cpage= ($this->p_cpage > $this->p_tpage) ? $this->p_tpage : $this->p_cpage ;		//当前页面
			$this->p_cpage = $f_cpage ? $f_cpage : 1 ;
			
			//页面数
			$this->p_tpage = ceil($this->p_count/$this->p_size);
			$from = ($this->p_cpage-1)*$this->p_size;
			$to = $this->p_size;
			
			$sql2 = "SELECT ".$field." FROM ".$table.$where.$order.' LIMIT '.$from.','.$to;
			$this->output_sql = $sql2;
			$data = $this->db->getAll($sql2);
		}else{
			$this->p_cpage = 0;
			$this->p_tpage = 0;
		}

		$this->isexecute = 1;
		return $data;
	}
	
	/**
	 * 通过已有的数据输出分页信息
	 *
	 * @param array $data
	 * @param int $cpage
	 * @param int $size
	 * @return array
	 */
	public function from_data($data,$cpage=1,$size=20){
		$this->p_count = count($data);
		$this->p_cpage = intval($cpage) ? intval($cpage) : '1';
		$this->p_cpage = ($this->p_cpage > $this->p_count) ? '1' : $this->p_cpage;
		$this->p_size = intval($size);
		
		$this->p_tpage = ceil($this->p_count/$this->p_size);
		$ref = $this->p_cpage-1;
		$this->isexecute = 1;
		
		$from = $this->p_size*($this->p_cpage-1);
		$to = 	$this->p_size*$this->p_cpage -1;
		$output = array();
		for($i=$from;$i<=$to;$i++){
			if($data[$i])
			$output[] = $data[$i];
		}
		return $output;
	}
	
	//内容页专用分页,不生成?格式
	public function get_content_page($data,$root){
		if(!$this->isexecute){
			my_jump('非法操作');
		}
		$tail = strstr($root,'-') ? '_cpage_' : '-cpage_';
		$first_page = "<a href='".$root.$tail."1.htm'>".$this->p_first_string."</a>";
		$last_page  = "<a href='".$root.$tail.$this->p_tpage.".htm'>".$this->p_last_string."</a>";
		$pre_page   = "<a href='".$root.$tail.($this->p_cpage-1).".htm'>".$this->p_pre_string."</a>";
		$next_page  = "<a href='".$root.$tail.($this->p_cpage+1).".htm'>".$this->p_next_string."</a>";
	
		if($this->p_cpage == $this->p_tpage){
			$next_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_next_string."</a>";
			$last_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_last_string."</a>";
		}
		
		if (1 == $this->p_cpage){
			$first_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_first_string."</a>";
			$pre_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_pre_string."</a>";
		}
		
		if($this->p_count > 0){
			
			//判断是否前段和后段
			$check=$this->p_display - $this->p_cpage - ($this->p_display-1)/2;
			$check1=$this->p_cpage + ($this->p_display-1)/2 - $this->p_tpage;
			
			if($this->p_tpage <= $this->p_display){
				$page_to = $this->p_tpage;
				$page_from =1;
				
			}else{
				
				//前段
				if($check >= 0){
					$page_to = $this->p_display;
					$page_from =1;
				//后段
				}elseif($check1 >= 0){
					$page_to = $this->p_tpage;
					$page_from = $this->p_tpage - $this->p_display+1;
				//中段
				}else{
					$page_from = $this->p_cpage - ($this->p_display-1)/2;
					$page_to = $this->p_cpage + ($this->p_display-1)/2;
				}

				if($page_from < 1){
					$page_to = $page_to - $page_from;
					if( $this->p_tpage <= $page_to){
						$page_to = $this->p_tpage;
					}
					$page_from = 1;
				}
			}
				
			for($kk=$page_from;$kk<=$page_to;$kk++){
				if($this->p_cpage == $kk)
				$page_list .= '<a class="cur" href="javascript:void(0)"><span>'.$kk.'</span></a>';
				else
				$page_list .= "<a href='".$root.$tail.$kk.".htm'><span>{$kk}</span></a>";
			}
			
			//下拉跳转
			if($this->isoption){	
				$options = "<span><select name='select_page' id='select_page' style='width:40px;font-size:10px;' onchange='window.location.href=\"{$root}{$tail}.htm\"+this.value+\"\"'>";
				for($pp=1;$pp<=$this->p_tpage;$pp++)
				{
					$select_type = '';
					if($pp == $this->p_cpage)
					{
						$select_type = "selected=\"selected\"";
					}
					$options .= "<option value='".$pp."' ".$select_type.">".$pp."</option>";
				}
				$options .= "</select></span>";
			}
				
			//$page_menu  = "【&nbsp;总记录&nbsp;".$this->p_count."&nbsp;条&nbsp;&nbsp;&nbsp;".
			//$page_menu  = "共&nbsp;".$this->p_tpage."&nbsp;页&nbsp;】&nbsp;&nbsp;&nbsp;&nbsp;".
			$page_menu .= $first_page;
			$page_menu .= $pre_page;
			$page_menu .= $page_list;
			$page_menu .= $next_page;
			$page_menu .= $last_page."&nbsp;";				
			$page_menu .= $options;
		}
		return $page_menu;
	}
	/**
	 * 获取分页导航
	 *
	 * @param array $data
	 * @param string $root
	 * @return string
	 */	
	
	public function get_page($data,$root){
		if(!$this->isexecute){
			my_jump('非法操作');
		}
		$tail = strstr($root,'?') ? '&cpage=' : '?cpage=';
		$first_page = "<a class='first-page' href='".$root.$tail."1'>".$this->p_first_string."</a>";
		$last_page  = "<a class='end-page' href='".$root.$tail.$this->p_tpage."'>".$this->p_last_string."</a>";
		$pre_page   = "<a class='up-page' href='".$root.$tail.($this->p_cpage-1)."'>".$this->p_pre_string."</a>";
		$next_page  = "<a class='next-page' href='".$root.$tail.($this->p_cpage+1)."'>".$this->p_next_string."</a>";
	
		if($this->p_cpage == $this->p_tpage){
			$next_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_next_string."</a>";
			$last_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_last_string."</a>";
		}
		
		if (1 == $this->p_cpage){
			$first_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_first_string."</a>";
			$pre_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_pre_string."</a>";
		}
		
		if($this->p_count > 0){
			
			//判断是否前段和后段
			$check=$this->p_display - $this->p_cpage - ($this->p_display-1)/2;
			$check1=$this->p_cpage + ($this->p_display-1)/2 - $this->p_tpage;
			
			if($this->p_tpage <= $this->p_display){
				$page_to = $this->p_tpage;
				$page_from =1;
				
			}else{
				
				//前段
				if($check >= 0){
					$page_to = $this->p_display;
					$page_from =1;
				//后段
				}elseif($check1 >= 0){
					$page_to = $this->p_tpage;
					$page_from = $this->p_tpage - $this->p_display+1;
				//中段
				}else{
					$page_from = $this->p_cpage - ($this->p_display-1)/2;
					$page_to = $this->p_cpage + ($this->p_display-1)/2;
				}

				if($page_from < 1){
					$page_to = $page_to - $page_from;
					if( $this->p_tpage <= $page_to){
						$page_to = $this->p_tpage;
					}
					$page_from = 1;
				}
			}
				
			for($kk=$page_from;$kk<=$page_to;$kk++){
				if($this->p_cpage == $kk)
				$page_list .= '<a class="cur" href="javascript:void(0)"><span>'.$kk.'</span></a>';
				else
				$page_list .= "<a href='".$root.$tail.$kk."'><span>{$kk}</span></a>";
			}
			
			//下拉跳转
			if($this->isoption){	
				$options = "<span><select name='select_page' id='select_page' style='width:50px;font-size:10px;' onchange='window.location.href=\"{$root}{$tail}\"+this.value+\"\"'>";
				for($pp=1;$pp<=$this->p_tpage;$pp++)
				{
					$select_type = '';
					if($pp == $this->p_cpage)
					{
						$select_type = "selected=\"selected\"";
					}
					$options .= "<option value='".$pp."' ".$select_type.">".$pp."</option>";
				}
				$options .= "</select></span>";
			}
				
			if($this->issum){
				//$page_menu = "<span>【总记录&nbsp;".$this->p_count."&nbsp;条&nbsp;&nbsp;&nbsp;";
				//$page_menu .= "共&nbsp;".$this->p_tpage."&nbsp;页】&nbsp;</span>";
                                $page_menu = "<span>【&nbsp;<strong>".$this->p_count."</strong>&nbsp;条记录&nbsp;|";
				$page_menu .= "&nbsp;共&nbsp;<strong>".$this->p_tpage."</strong>&nbsp;页】&nbsp;</span>";
			}
			$page_menu .= $first_page;
			$page_menu .= $pre_page;
			$page_menu .= $page_list;
			$page_menu .= $next_page;
			$page_menu .= $last_page."&nbsp;";				
			$page_menu .= $options;
		}
		return $page_menu;
	}
	
	
	public function get_page2($data,$root){
		if(!$this->isexecute){
			my_jump('非法操作');
		}
		$tail = strstr($root,'?') ? '&cpage=' : '?cpage=';		
	
		if($this->p_cpage == $this->p_tpage){			
			$next_page = '<li class="next disabled"><a href="javascript:void(0)" title="下一页">&gt;</a></li>';		
			$next_page2 = '<a href="javascript:void(0)">下一页</a></li>';
		}else{
			$next_page = '<li class="next"><a href="'.$root.$tail.($this->p_cpage+1).'" title="下一页">&gt;</a></li>';	
			$next_page2 = '<a href="'.$root.$tail.($this->p_cpage+1).'">下一页</a>';			
		}
		
		if (1 == $this->p_cpage){
			$pre_page = '<li class="prev disabled" title="上一页"><a href="javascript:void(0)">&lt;</a></li>	';
			$pre_page2 = '<a href="javascript:void(0)">上一页</a></li>';
		}else{
			$pre_page = '<li class="prev " title="上一页"><a href="'.$root.$tail.($this->p_cpage-1).'">&lt;</a></li>	';	
			$pre_page2 = '<a href="'.$root.$tail.($this->p_cpage-1).'">上一页</a>';				
		}
		
		//页面序列
		$page_from =1;
		$page_to = $this->p_tpage;
		for($kk=$page_from;$kk<=$page_to;$kk++){
				if($this->p_cpage == $kk)
				$page_list .= '<li class="active"><a href="javascript:void(0)" title="第'.$kk.'页">'.$kk.'</a></li>';				
				else
				$page_list .= '<li><a href="'.$root.$tail.$kk.'" title="第'.$kk.'页" >'.$kk.'</a></li>';					
		}
			
		
		
		
		
		if($this->p_count > 0){
			$page_menu = '<div class="pagination"><ul>';
			$page_menu .= $pre_page;
			$page_menu .= $page_list;
			$page_menu .= $next_page;
			$page_menu .= '</ul></div>';		
					
			$this->top_page = '<div class="shop-tool-page">
                            <span>共<em>'.$this->p_count.'</em>件商品</span>
                            <span><em>'.$this->p_cpage.'</em>/'.$this->p_tpage.'</span>'.$pre_page2.$next_page2.'</div>';
			
							
		}
		return $page_menu;
	}
	
	public function get_page3($data){
		
		if(!$this->isexecute){
			my_jump('非法操作');
		}
		
		if($this->p_cpage == $this->p_tpage){			
			$next_page = '<li class="next disabled"><a href="javascript:void(0)" title="下一页">&gt;</a></li>';
		}else{
			$next_page = '<li class="next"><a href="javascript:void(0)"  onclick="javascript:$(function(){load_data('.($this->p_cpage+1).');})" title="下一页">&gt;</a></li>';
		}
		
		if (1 == $this->p_cpage){
			$pre_page = '<li class="prev disabled" title="上一页"><a href="javascript:void(0)">&lt;</a></li>	';			
		}else{
			$pre_page = '<li class="prev " title="上一页"><a href="javascript:void(0)" onclick="javascript:$(function(){load_data('.($this->p_cpage-1).');})" >&lt;</a></li>	';							
		}
		
		//页面序列
		$page_from =1;
		$page_to = $this->p_tpage;
		for($kk=$page_from;$kk<=$page_to;$kk++){
				if($this->p_cpage == $kk)
				$page_list .= '<li class="active"><a href="javascript:void(0)" title="第'.$kk.'页">'.$kk.'</a></li>';				
				else
				$page_list .= '<li><a href="javascript:void(0)"  onclick="javascript:$(function(){load_data('.$kk.');})" title="第'.$kk.'页" >'.$kk.'</a></li>';					
		}
		
		
		if($this->p_count > 0){
			$page_menu = '<div class="pagination"><ul>';
			$page_menu .= $pre_page;
			$page_menu .= $page_list;
			$page_menu .= $next_page;
			$page_menu .= '</ul></div>';			
							
		}		
		return $page_menu;
	}
	
	
	/**
	 * 获取分页导航
	 *
	 * @param array $data
	 * @param string $root
	 * @return string
	 */
	public function get_friend_page($data,$root){
		if(!$this->isexecute){
			my_jump('非法操作');
		}
		$tail = strstr($root,'?') ? '&cpage=' : '?cpage=';
		$first_page = "<a class='first-page' href='".$root.$tail."1'>".$this->p_first_string."</a>";
		$last_page  = "<a class='end-page' href='".$root.$tail.$this->p_tpage."'>".$this->p_last_string."</a>";
		$pre_page   = "<a class='up-page' href='".$root.$tail.($this->p_cpage-1)."'>".$this->p_pre_string."</a>";
		$next_page  = "<a class='next-page' href='".$root.$tail.($this->p_cpage+1)."'>".$this->p_next_string."</a>";
	
		if($this->p_cpage == $this->p_tpage){
			$next_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_next_string."</a>";
			$last_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_last_string."</a>";
		}
		
		if (1 == $this->p_cpage){
			$first_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_first_string."</a>";
			$pre_page = "<a class='noturn' onclick='javascript:void(0)'>".$this->p_pre_string."</a>";
		}
		
		if($this->p_count > 0){
			
			//判断是否前段和后段
			$check=$this->p_display - $this->p_cpage - ($this->p_display-1)/2;
			$check1=$this->p_cpage + ($this->p_display-1)/2 - $this->p_tpage;
			
			if($this->p_tpage <= $this->p_display){
				$page_to = $this->p_tpage;
				$page_from =1;
				
			}else{
				
				//前段
				if($check >= 0){
					$page_to = $this->p_display;
					$page_from =1;
				//后段
				}elseif($check1 >= 0){
					$page_to = $this->p_tpage;
					$page_from = $this->p_tpage - $this->p_display+1;
				//中段
				}else{
					$page_from = $this->p_cpage - ($this->p_display-1)/2;
					$page_to = $this->p_cpage + ($this->p_display-1)/2;
				}

				if($page_from < 1){
					$page_to = $page_to - $page_from;
					if( $this->p_tpage <= $page_to){
						$page_to = $this->p_tpage;
					}
					$page_from = 1;
				}
			}
				
			for($kk=$page_from;$kk<=$page_to;$kk++){
				if($this->p_cpage == $kk)
				$page_list .= '<a class="cur" href="javascript:void(0)"><span>'.$kk.'</span></a>';
				else
				$page_list .= "<a href='".$root.$tail.$kk."'><span>{$kk}</span></a>";
			}
			
			//下拉跳转
			if($this->isoption){	
				$options = "<span><select name='select_page' id='select_page' style='width:50px;font-size:10px;' onchange='window.location.href=\"{$root}{$tail}\"+this.value+\"\"'>";
				for($pp=1;$pp<=$this->p_tpage;$pp++)
				{
					$select_type = '';
					if($pp == $this->p_cpage)
					{
						$select_type = "selected=\"selected\"";
					}
					$options .= "<option value='".$pp."' ".$select_type.">".$pp."</option>";
				}
				$options .= "</select></span>";
			}
				
			if($this->issum){
				//$page_menu = "<span>【总记录&nbsp;".$this->p_count."&nbsp;条&nbsp;&nbsp;&nbsp;";
				//$page_menu .= "共&nbsp;".$this->p_tpage."&nbsp;页】&nbsp;</span>";
                                $page_menu = "<span>【&nbsp;<strong>".$this->p_count."</strong>&nbsp;条记录&nbsp;|";
				$page_menu .= "&nbsp;共&nbsp;<strong>".$this->p_tpage."</strong>&nbsp;页】&nbsp;</span>";
			}
			
			$page_menu .= $pre_page;		
			$page_menu .= $next_page;			
		}
		return $page_menu;
	}
	
	//前端分页	
	public function get_index_page($data,$root){
		if(!$this->isexecute){
			my_jump('非法操作');
		}
				
		$tail = strstr($root,'?') ? '&cpage=' : '?cpage=';
		//$first_page = "<a href='".$root.$tail."1'>1</a>";
		//$last_page  = "<a href='".$root.$tail.$this->p_tpage."'>".$this->p_tpage."</a>";
		$pre_page   = "<a href='".$root.$tail.($this->p_cpage-1)."'>上一页</a>";
		$next_page  = "<a href='".$root.$tail.($this->p_cpage+1)."'>下一页</a>";
	
		if($this->p_cpage == $this->p_tpage){
			$next_page = '<span class="disabled">下一页</span>';
			//$last_page = '<span class="current">'.$this->p_tpage.'</span>';
		}
		
		if (1 == $this->p_cpage){
			//$first_page = '';
			$pre_page = '<span class="disabled">上一页</span>';
		}
		
		if($this->p_count > 0){
			
			//判断是否前段和后段
			$check=$this->p_display - $this->p_cpage - ($this->p_display-1)/2;
			$check1=$this->p_cpage + ($this->p_display-1)/2 - $this->p_tpage;
			
			if($this->p_tpage <= $this->p_display){
				$page_to = $this->p_tpage;
				$page_from =1;
				
			}else{
				
				//前段
				if($check >= 0){
					$page_to = $this->p_display;
					$page_from =1;
				//后段
				}elseif($check1 >= 0){
					$page_to = $this->p_tpage;
					$page_from = $this->p_tpage - $this->p_display+1;
				//中段
				}else{
					$page_from = $this->p_cpage - ($this->p_display-1)/2;
					$page_to = $this->p_cpage + ($this->p_display-1)/2;
				}

				if($page_from < 1){
					$page_to = $page_to - $page_from;
					if( $this->p_tpage <= $page_to){
						$page_to = $this->p_tpage;
					}
					$page_from = 1;
				}
			}
			
			if($page_from > 1){
				$first_page = "<a href='".$root.$tail."1'>1</a>";
				$page_list .= "<a href='".$root.$tail.($page_from-1)."'>...</a>";	
			} 
				
			for($kk=$page_from;$kk<=$page_to;$kk++){			
				if($this->p_cpage == $kk)
				$page_list .= '<span class="current">'.$kk.'</span>';				
				else
				$page_list .= "<a href='".$root.$tail.$kk."'>{$kk}</a>";
			}
			
			if($page_to < $this->p_tpage){
				$page_list .= "<a href='".$root.$tail.($page_to+1)."'>...</a>";
				$last_page  = "<a href='".$root.$tail.$this->p_tpage."'>".$this->p_tpage."</a>";
				
			} 
			$page_menu = '<div class="pages" id="pages">';
			$page_menu .= $pre_page;
			$page_menu .= $first_page;
			
			$page_menu .= $page_list;
			
			$page_menu .= $last_page;	
			$page_menu .= $next_page;			
			$page_menu .= '</div>';
		}
		return $page_menu;
	}
	
	//前端wap分页	
	public function get_wap_page($data,$root){
		if(!$this->isexecute){
			my_jump('非法操作');
		}
				
		$tail = strstr($root,'?') ? '&cpage=' : '?cpage=';
		$pre_page = '<span class="pre">上一页</span>';	
		$pre_page   = "<span class='pre'><a href='".$root.$tail.($this->p_cpage-1)."'>上一页</a></span>";
		$next_page  = "<span><a href='".$root.$tail.($this->p_cpage+1)."'>下一页</a></span>";
	
		if($this->p_cpage == $this->p_tpage){
			$next_page = '<span>下一页</span>';
			//$last_page = '<span class="current">'.$this->p_tpage.'</span>';
		}
		
		if (1 == $this->p_cpage){
			//$first_page = '';
			$pre_page = '<span class="pre">上一页</span>';
		}
		
		if($this->p_count > 0){
			
		
			$page_menu = '<div class="wapPage">';
			$page_menu .= $pre_page;		
			$page_menu .= $next_page;			
			$page_menu .= '</div>';
		}
		return $page_menu;
	}
	
	
	
	/**
	 * 获取总记录数
	 *
	 * @return int 
	 */
	public function get_record_count(){
		return $this->p_count;
	}
	
	/**
	 * 获取总页数
	 *
	 * @return int
	 */
	public function get_page_count(){
		return $this->p_tpage;
	}
	
	/**
	 * 获取当前页
	 *
	 * @return int
	 */
	public function get_cpage(){
		return $this->p_cpage;
	}
	
	/**
	 * 设定分页导航数量
	 *
	 * @param int $page
	 */
	public function set_display_page($page=10){
		$this->p_display = $page;
	}
	
	/**
	 * 是否显示下拉分页
	 *
	 * @param int $type
	 */
	public function set_option($type=1){
		$this->isoption = intval($type);
	}

	/**
	 * 是否显示记录总量
	 *
	 * @param int $type
	 */
	public function set_sum($type=1){
		$this->issum = intval($type);
	}

	public function get_sql(){
		return $this->output_sql;
	}
	
	public function get_top_page(){
		return $this->top_page;
	}
}


//example
/*
$MyPage = new Mypage($db);
$data = $MyPage->from_sql('*','sys_sort',"sort_id > '5'","sort_root_id,sort_id",intval($_GET['cpage']),20);
$ary = array('news1','news2','news3');
//$data = $MyPage->from_data($ary,$cpage);
//$MyPage->set_option(1);
$page = $MyPage->get_page($data,$cf_self_path.'-act_list_rid_'.$rid.'.htm');
*/
?>
